<?php

namespace app\api\controller\event;
use app\api\service\event\MerchantService;
use think\Request;

class Merchant
{
    protected $Service;
    public function __construct()
    {
        $this->Service = MerchantService::getInstance();
    }


    /**
     * 商户注册
     * @param Request $request
     * @param('company','公司名称','require')
     * @param('phone','手机号','require|mobile')
     * @param('account','账号','require')
     * @param('password','密码','require')
     * @return \think\response\Json
     */
    public function merchantRegister(Request $request){
       $params  = $request->post();
       $result = $this->Service->merchantRegister($params);
       return writeJson(201, $result, '申请成功');
    }



    /**
     * @auth('查询商户信息','商户管理')
     * @param Request $request
     * @return \think\response\Json
     */
    public function merchantInfo(){
        $result = $this->Service->merchantInfo();
        return writeJson(201, $result, '数据');
    }


    /**
     * @auth('商户商品列表','商户管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getMerchantProduct(Request $request){
        $params  = $request->get();
        $result = $this->Service->getMerchantProduct($params);
        return writeJson(201, $result, '数据列表');
    }



    /**
     * @auth('创建商户商品','商户管理')
     * @param Request $request
     * @param('title','商品名称','require')
     * @param('url','商品链接','require')
     * @return \think\response\Json
     */
    public function createMerchantProduct(Request $request){
        $params  = $request->post();
        $this->Service->createMerchantProduct($params);
        return writeJson(201, '', '商品创建成功');
    }

    /**
     * @auth('编辑商户商品','商户管理')
     * @param Request $request
     * @param('id','商品id','require')
     * @param('title','商品名称','require')
     * @param('url','商品链接','require')
     * @return \think\response\Json
     */
    public function updateMerchantProduct(Request $request){
        $params  = $request->param();
        $this->Service->updateMerchantProduct($params);
        return writeJson(201, '', '商品编辑成功');
    }



    /**
     * @auth('商户订单列表','商户管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getMerchantOrder(Request $request){
        $params  = $request->get();
        $result = $this->Service->getMerchantOrder($params);
        return writeJson(201, $result, '数据列表');
    }



    /**
     * @auth('创建商户订单','商户管理')
     * @param Request $request
     * @param('product_id','商品id')
     * @param('material_ids','素材数组id','array')
     * @param('data','业务平台信息','require|array')
     * @return \think\response\Json
     */
    public function createMerchantOrder(Request $request){
        $params  = $request->post();
        $this->Service->createMerchantOrder($params);
        return writeJson(201, '', '创建商户订单成功');
    }


    /**
     * @auth('编辑商户订单','商户管理')
     * @param Request $request
     * @param('id','订单id','require')
     * @param('product_id','商品id')
     * @param('material_ids','素材数组id','array')
     * @param('data','业务平台信息','require|array')
     * @return \think\response\Json
     */
    public function updateMerchantOrder(Request $request){
        $params  = $request->param();
        $this->Service->updateMerchantOrder($params);
        return writeJson(201, '', '创建商户订单成功');
    }


    /**
     * @auth('商户素材管理列表','商户管理')
     * @param Request $request
     * @param('page','页数','require')
     * @param('material_ids','素材数组','array')
     * @param('type','类型','number')
     * @return \think\response\Json
     */
    public function getMerchantMaterial(Request $request){
        $params = $request->get();
        $result = $this->Service->getMerchantMaterial($params);
        return writeJson(201, $result, '数据列表');
    }



    /**
     * @auth('商户素材新增','商户管理')
     * @param Request $request
     * @param('product_id','商品id','require')
     * @param('materials','素材','require|array')
     * @return \think\response\Json
     */
    public function createMerchantMaterial(Request $request){
        $params = $request->post();
        $this->Service->createMerchantMaterial($params);
        return writeJson(201, '', '素材添加成功');
    }


    /**
     * @auth('商户素材删除','商户管理')
     * @param $id
     * @return \think\response\Json
     */
    public function deleteMerchantMaterial($id){
        $this->Service->deleteMerchantMaterial($id);
        return writeJson(201, '', '素材删除成功');
    }


    /**
     * @auth('火箭豆日志','商户管理')
     * @param Request $request
     * @param('page','页数','require')
     * @param('merchant_id','商户id','number')
     * @return \think\response\Json
     */
    public function getPropertyLog(Request $request){
        $params = $request->get();
        $result = $this->Service->getPropertyLog($params);
        return writeJson(201, $result, '数据列表');
    }


    /**
     * @auth('商户数据分析','商户管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getDataAnalysis(Request $request){
        $params = $request->get();
        $result = $this->Service->getDataAnalysis($params);
        return writeJson(201, $result, '数据列表');
    }


    /**
     * @auth('商户订单数据分析','商户管理')
     * @param Request $request
     * @param('order_id','订单id','require')
     * @return \think\response\Json
     */
    public function getOrderAnalysis(Request $request){
        $params = $request->get();
        $result = $this->Service->getOrderAnalysis($params);
        return writeJson(201, $result, '数据');
    }


}
